#include <stdio.h>
#include <malloc.h>
#include <stdbool.h>
#include <time.h>

typedef int ElementType;
struct QNode{
    ElementType *data; //?洢????????
    int front,rear;  //???е? ? β ???
    int MAXSIZE;   //???е????????
};
typedef struct QNode *Queue;

Queue  createQueue(int MAXSIZE) {
    //???????????
    Queue Q = (Queue)malloc(sizeof (struct QNode));
    Q->data = (ElementType*) malloc(MAXSIZE * sizeof (ElementType));
    srand((unsigned )time(NULL));
    int x = rand()  % 8;

    Q->front = Q->rear = x;
    Q->MAXSIZE = MAXSIZE;
    return Q;
}
bool isFull(Queue Q) {
    return ((Q->rear+1)%Q->MAXSIZE == Q->front);
}
bool AddQ(Queue Q,ElementType x) {
    if(isFull(Q)) {
        printf("队列满!");
        return false;
    } else {
        Q->rear = (Q->rear + 1) % Q->MAXSIZE;
        Q->data[Q->rear] = x;
        return true;
    }
}
bool isEmpty(Queue Q) {
    return (Q->rear == Q->front);
}

ElementType DeleteQ(Queue Q) {
    if(isEmpty(Q)) {
        return false;
    } else {
        Q->front = (Q->front + 1) % Q->MAXSIZE;
        return Q->data[Q->front];
    }
}

int main() {
    Queue Q1;
    Q1 = createQueue(7);
    AddQ(Q1,3);
    AddQ(Q1,4);
    AddQ(Q1,6);
    AddQ(Q1,3);

    AddQ(Q1,4);
    printf("%d\n",Q1->data[Q1->rear]);
    printf("%d %d",Q1->rear,Q1->front);
    return 0;
}
